package com.example.controller;

import com.example.domain.Result;
import com.example.domain.Account;
import com.example.domain.MsgEmail;
import com.example.service.AccountService;
import com.example.service.MsgServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/msg")
@CrossOrigin
public class MsgController {
    @Autowired
    AccountService accountService;

    @Autowired
    private MsgServiceImpl msgService;

    @GetMapping("/{email}")
    public Result getCode(@PathVariable String email){
        Result result;
       result = accountService.haveAccount(email);
       if(result.getFlag()){
         return msgService.sendCode(email);
       }
       return new Result(false,"该账号已注册!");
    }

    @GetMapping("/{email}/{code}")
    @ResponseBody
    public Result checkCode(MsgEmail msgEmail){
        return msgService.checkCode(msgEmail);
    }
    @PostMapping ("/submit")
    @ResponseBody
    public Result saveAccount(@RequestBody Account account){
        return accountService.save1(account);
    }
}
